<?php
	require_once('../inc/fen_fns.php');
	sec_session_start();
	
	if(login_check($mysqli, '>', '50') == true) {

		if ($_SESSION['access_level'] == '50') {
			
			$query = $_DB->Query("SELECT faculty_id from fen_members where id = '".$_SESSION['user_id']."'");
			$faculty_id = "and fen_faculty.id = ".$_DB->GetResultValue($query, "0", "faculty_id");
			
		} else {
			if ($_POST['faculty_id']) { $faculty_id = "and fen_faculty.id = ".$_POST['faculty_id']; } else { $faculty_id = ""; }
		}
		
		if ($_POST['name']) { $name = "and fen_members.name LIKE '%".$_POST['name']."%'"; } else { $name = ""; }
		if ($_POST['surname']) { $surname = "and fen_members.surname LIKE '%".$_POST['surname']."%'"; } else { $surname = ""; }
		if ($_POST['department_id']) { $department_id = "and fen_department.id = ".$_POST['department_id']; } else { $department_id = ""; }
		if ($_POST['toplanti_adi']) { $toplanti_adi = "and fen_toplanti.toplanti_adi LIKE '%".$_POST['toplanti_adi']."%'"; } else { $toplanti_adi = ""; }
		if ($_POST['ulke']) { $ulke = "and fen_toplanti.ulke LIKE '".$_POST['ulke']."%'"; } else { $ulke = ""; }
		
		if ($_POST['tarih1']) { $tarih1 = split('/', $_POST['tarih1']); $tarih1 = $tarih1[2].'-'.$tarih1[1].'-'.$tarih1[0];	$tarih1 = "and ('".$tarih1."' BETWEEN fen_toplanti.tarih1 AND fen_toplanti.tarih2 OR '".$tarih1."' <= fen_toplanti.tarih1)"; } else { $tarih1 = ""; }	
		if ($_POST['tarih2']) { $tarih2 = split('/', $_POST['tarih2']); $tarih2 = $tarih2[2].'-'.$tarih2[1].'-'.$tarih2[0];	$tarih2 = "and ('".$tarih2."' BETWEEN fen_toplanti.tarih1 AND fen_toplanti.tarih2 OR '".$tarih2."' >= fen_toplanti.tarih2)"; } else
		//if ($_POST['tarih2']) { $tarih2 = split('/', $_POST['tarih2']); $tarih2 = $tarih2[2].'-'.$tarih2[1].'-'.$tarih2[0];	$tarih2 = "and fen_toplanti.tarih2 <= '".$tarih2."'"; } else { $tarih2 = ""; }

			
		if ($_POST['bildiri_konusu']) { $bildiri_konusu = "and fen_toplanti.bildiri_konusu LIKE '%".$_POST['bildiri_konusu']."%'"; } else { $bildiri_konusu = ""; }
		if ($_POST['destek_turu']) { $destek_turu = "and fen_toplanti.destek_turu LIKE '".$_POST['destek_turu']."%'"; } else { $destek_turu = ""; }
		if ($_POST['ders_durumu']) { $ders_durumu = "and fen_toplanti.ders_durumu LIKE '".$_POST['ders_durumu']."%'"; } else { $ders_durumu = ""; }
		
		if ($_POST['user_id']) {
			$query = $_DB->Query("SELECT fen_members.name, fen_members.surname, fen_members.titr, fen_faculty.faculty_name, fen_department.department_name FROM fen_members, fen_faculty, fen_department where fen_members.id = '".$_POST['user_id']."' and fen_members.faculty_id = fen_faculty.id and fen_members.department_id = fen_department.id");
			$tablehead = $_DB->GetResultValue($query, "0", "titr")." ".$_DB->GetResultValue($query, "0", "name")." ".$_DB->GetResultValue($query, "0", "surname")." Yayınları";
		} else {
			$tablehead = "Rapor";
		}


?>

	<script type="text/javascript">


var oTable;

$(document).ready(function() {

    $(".contentTopArea").hide();

    $('.buttonAdd').click(function(){
    	$(".contentTopArea").slideToggle(150);
    });

	
    oTable = $('#example').dataTable( {
		"sPaginationType": "full_numbers",
		"sDom": 'f<"toolbar">Trtlip',
		"oTableTools": {
			"aButtons": [
				"xls"
			]
		}
	} );

	$("div.toolbar").html('');
	
});

function showUser(obj) {  

	jQuery(document).ready(function($) {
		  $('a[rel*=facebox]').facebox() 

		  jQuery.facebox({ ajax: 'reports/meeting-detailed.php?pid='+obj })
	}) 
} 

</script>	
	<br><br><button class="buttonAdd" id="buttonAdd" type="button">Yeni Rapor Al</button><br><br><br>
	
			<div class="showtable">
				<div id="summaryTableBigTopp">
					<?php echo $tablehead; ?>
				</div>
			<form id="form">
				<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
						<thead>
							<tr>
								
								<th>#</th>
								<th>Fakülte</th>
								<th>Bölüm</th>
								<th>Ünvan</th>
								<th>Ad</th>
								<th>Soyad</th>
								<th>Toplantı Adı</th>
								<th>Ülke</th>
								<th>Toplantı<br>Başlangıç</th>
								<th>Toplantı<br>Bitiş</th>
								<th>Ders Durumu</th>
								<th>İstenen tutar</th>
								<th>BAU'nun<br>Ödediği Tutar</th>
								<th>Detay</th>
							</tr>
						</thead>
						<tbody>
						
<?php 
						$query = $_DB->Query("SELECT
											fen_members.titr as titr,
											fen_members.name as name,
											fen_members.surname as surname,
											fen_members.username as username,
											fen_department.department_name as department_name,
											fen_faculty.faculty_name as faculty_name,
											fen_toplanti.id as id,
											fen_toplanti.toplanti_adi as toplanti_adi,
											fen_toplanti.ulke as ulke,
											date_FORMAT(fen_toplanti.tarih1, '%d/%m/%Y') as tarih1,		
											date_FORMAT(fen_toplanti.tarih2, '%d/%m/%Y') as tarih2,
											fen_toplanti.bildiri_konusu as bildiri_konusu,
											fen_toplanti.destek_turu as destek_turu,
											fen_toplanti.ders_durumu as ders_durumu,
											fen_toplanti.tutar as tutar,
											fen_toplanti.odenen_tutar as odenen_tutar,
											fen_toplanti.para_birimi as para_birimi
											from fen_members, fen_department, fen_faculty, fen_toplanti
											WHERE
											fen_toplanti.member_id = fen_members.id and
											fen_members.department_id = fen_department.id and
											fen_members.faculty_id = fen_faculty.id
											$faculty_id
											$department_id
											$name
											$surname
											$toplanti_adi
											$ulke
											$tarih1
											$tarih2
											$bildiri_konusu
											$destek_turu
											$ders_durumu
											$user_id
											ORDER BY fen_toplanti.id DESC");

						$count = $_DB->GetResultNumber($query);
						
						$date = date("d F Y",strtotime($myrow['date']));
						
						

						for ($i=0; $i<$count; $i++)
						{
							
							$no = $i + 1;
							
							if ($_DB->GetResultValue($query, $i, "odenen_tutar") > 0) {
								$odenen = $_DB->GetResultValue($query, $i, "odenen_tutar")." ".$_DB->GetResultValue($query, $i, "para_birimi");
							} else {
								$odenen = "Henüz ödenmedi";
							}
							
							/*
							if ($_DB->GetResultValue($query, $i, "titr") == 'Prof. Dr.') {
								$titr = "<p id=\"hiddentitr\">1</p>Prof. Dr.";
							} else if ($_DB->GetResultValue($query, $i, "titr") == 'Doç. Dr.') {
								$titr = "<p id=\"hiddentitr\">2</p>Doç. Dr.";
							} else if ($_DB->GetResultValue($query, $i, "titr") == 'Yard. Doç. Dr.') {
								$titr = "<p id=\"hiddentitr\">3</p>Yard. Doç. Dr.";
							} else if ($_DB->GetResultValue($query, $i, "titr") == 'Öğr. Gör. Dr.') {
								$titr = "<p id=\"hiddentitr\">4</p>Öğr. Gör. Dr.";
							} else if ($_DB->GetResultValue($query, $i, "titr") == 'Öğr. Gör.') {
								$titr = "<p id=\"hiddentitr\">5</p>Öğr. Gör.";
							} else if ($_DB->GetResultValue($query, $i, "titr") == 'Uzm.') {
								$titr = "<p id=\"hiddentitr\">6</p>Uzm.";
							} else if ($_DB->GetResultValue($query, $i, "titr") == 'Okutman') {
								$titr = "<p id=\"hiddentitr\">7</p>Okutman";
							} else if ($_DB->GetResultValue($query, $i, "titr") == 'Arş. Gör.') {
								$titr = "<p id=\"hiddentitr\">8</p>Arş. Gör.";
							}
							*/
							
							$titr = $_DB->GetResultValue($query, $i, "titr");
							
							echo "
								<tr>
									<td>".$no."</td>
									<td>".$_DB->GetResultValue($query, $i, "faculty_name")."</td>
									<td>".$_DB->GetResultValue($query, $i, "department_name")."</td>
									<td>".$titr."</td>
									<td>".$_DB->GetResultValue($query, $i, "name")."</td>
									<td>".$_DB->GetResultValue($query, $i, "surname")."</td>
									<td>".$_DB->GetResultValue($query, $i, "toplanti_adi")."</td>
									<td>".$_DB->GetResultValue($query, $i, "ulke")."</td>
									<td>".$_DB->GetResultValue($query, $i, "tarih1")."</td>
									<td>".$_DB->GetResultValue($query, $i, "tarih2")."</td>
									<td>".$_DB->GetResultValue($query, $i, "ders_durumu")."</td>
									<td class=\"center\">".$_DB->GetResultValue($query, $i, "tutar")." ".$_DB->GetResultValue($query, $i, "para_birimi")."</td>
									<td class=\"center\">".$odenen."</td>
									<td class=\"center\"><a class =\"user_detail_but\" onclick=\"showUser('".$_DB->GetResultValue($query, $i, "id")."')\" href=\"#\"><img id=\"editimg\" src=\"images/edit.gif\"></img></a></td>
		
								</tr>";		
						}
?>
						</tbody>
					</table>
					
				</form>
			<br><br>
			</div>
	</div>
	
<?php 

	} else {
		header('Location: ./index.php?error=2');
	}

?>	